package com.example.sport.controller;

import com.alibaba.fastjson.JSON;
import com.example.sport.pojo.User;
import com.example.sport.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {

    @Autowired
    UserService userService;

    @RequestMapping("/login")
    public String login(@RequestBody User user){
        String flag="error";
        Map<String,Object> res=new HashMap<>();

        User user1=userService.getUser(user.getUsername());
        if(user1!=null&&user1.getPassword().equals(user.getPassword()))
            flag="ok";
        res.put("flag",flag);
        res.put("user",user1);
        return flag;
    }
}
